package org.mapwar.common.tools;

/**
 * Created by zhebinwang on 2017/9/27.
 */

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonRootName;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.xml.bind.annotation.XmlRootElement;
import java.beans.Transient;
import java.util.Map;

/**
 * Created by xiaodong on 15/10/28.
 */
@XmlRootElement(name = "response")
@JsonRootName("returnData")
@JsonPropertyOrder({
        "errorCode",
        "data"
})
public class Reply {
    private String errorCode;
    private Object data;

    @JsonIgnore
    @Transient
    public boolean isError() {
        int eValue = Integer.valueOf(errorCode);
        ErrorCode eCode = ErrorCode.valueOf(eValue);
        return eCode == null ? true : eCode != ErrorCode.SUCCESS;
    }

    @JsonProperty("errorCode")
    public String getErrorCode() {
        return errorCode;
    }

    public Reply setErrorCode(String errorCode) {
        this.errorCode = errorCode;
        return this;
    }

    @JsonProperty("data")
    public Object getData() {
        return data;
    }

    public Reply setData(Object data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString(){
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
